package com.rzx.mybackend.service.Impl;

import com.rzx.mybackend.service.LoginService;
import com.rzx.mybackend.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * LoginServiceImpl
 *
 * @author renzhexian
 * @date 2025/7/15
 */
@Service
public class LoginServiceImpl implements LoginService {

    @Value("${jwt.secret-key}")
    private String secretKey;

    @Value("${jwt.expire-time}")
    private int expireTime;

    /**
     * 生成token
     * @param userName 用户名
     * @param authentication 角色信息
     * @return
     */
    @Override
    public String generateToken(String userName,String authentication) {

        HashMap<String, Object> claims = new HashMap<>();

        claims.put("userName", userName);
        claims.put("authentication", authentication);
        return JwtUtil.createJWT(secretKey,expireTime,claims);
    }
}
